package netbolt

import (
	"github.com/samuel/go-zookeeper/zk"
)

const (
	ZK_ROOT_PATH = "/netbolt"
	ZK_DB_PATH   = ZK_ROOT_PATH + "/dbs"
	//ZK_DB_SYSDB     = ZK_DB_PATH + "/sys"
	ZK_CLUSTER_PATH = ZK_ROOT_PATH + "/cluster"

	ZK_STATUS_PATH           = ZK_ROOT_PATH + "/status"
	ZK_CLUSTER_COMPLETE_PATH = ZK_STATUS_PATH + "/events"

	ZK_ONLINE_PATH = ZK_ROOT_PATH + "/onlines"
)

var (
	ZkConn    *zk.Conn
	ZkMonitor <-chan zk.Event
	OnZkEvent func(event *zk.Event)
)

func ZKCreateIfNotExist(path string, data []byte, flags int32, acl []zk.ACL) (string, error) {
	if exist, _, _ := ZkConn.Exists(path); !exist {

		return ZkConn.Create(path, data, flags, acl)
	} else {
		return path, nil
	}
}
